package cn.itcast.crm.dao;

import java.util.List;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;

import cn.itcast.crm.domain.Customer;

public interface CustomerRepository extends JpaRepository<Customer, Integer> {

	List<Customer> findByFixedAreaIdIsNull();

	List<Customer> findByFixedAreaId(String fixedAreaId);

	@Query(value="update Customer set fixedAreaId = null where fixedAreaId = ?1")
	@Modifying
	void clearFixedAreaId(String fixedAreaId);

	@Query(value="update Customer set fixedAreaId = ?1 where id = ?2")
	@Modifying
	void updateFixedAreaId(String fixedAreaId, Integer customerId);

    Customer findByTelephone(String telephone);

    @Query(value = "update Customer set type=1 where telephone=?1")
	@Modifying
	void updateType(String telephone);

    Customer findByTelephoneAndPassword(String telephone, String password);

	@Query("select fixedAreaId from Customer where address = ?1 and id = ?2")
	String findFixedIdByAddressAndCustomerId(String address, Integer customerId);

}
